Metering API
Metering service API Documentation
Version: 1.2.2
Paths
Healthcheck API -
/aiwb/metering/api/v1/healthz
- Method: GET
- Summary: Health Check
- Description: Return Health Status. :return:
- Operation ID: health_check_aiwb_metering_api_v1_healthz_get
- Responses:
- 200:
- Description: Successful Response
- Content-Type: application/json
- 200:
Create Metering -
Endpoint: /aiwb/metering/api/v1/
- Method:
POST
- Summary: Create Metering To Analyze Token Consumption
- Description: This API facilitates the logging of token consumption by tenants, users, and bots within the system. It allows for detailed tracking and analysis of token usage patterns, enabling administrators to monitor resource allocation efficiently. The endpoint supports specifying the relevant tenant, user, and bot identities for precise consumption tracking and auditing purposes.
- Operation ID:
Create_Metering_to_analyze_token_consumption_aiwb_metering_api_v1__post
Request Payload:
Type | Parameter | Description | Data Type | is_optional |
---|---|---|---|---|
Query | bot_id | Identifier of the chatbot | string | madatory |
Query | application_name | Name of the application using the chatbot | string | Optional |
Query | unique_query_id | ID for the query | string | Optional |
Query | user_query | User's input query | string | madatory |
Query | model_answer | Answer generated by the chatbot model | string | Optional |
Query | model_name | Name of the chatbot model used (OpenAI, Palm) | string | Optional |
Query | pre_calc_input_token | Number of input tokens pre-calculated | integer | Optional |
Query | input_token | Number of input tokens processed | integer | madatory |
Query | output_token | Number of output tokens generated | integer | madatory |
Query | input_payload | Additional input payload for the chatbot | string | madatory |
Query | model_response | Full response generated by the chatbot model | string | madatory |
Query | latency_in_seconds | Response latency in seconds | number | Optional |
Query | word_count_sent | Number of words in the user query | integer | Optional |
Query | word_count_received | Number of words in the chatbot's response | integer | Optional |
Query | toxicity | Toxicity level of the response | string | Optional |
Query | sentiment | Sentiment analysis result of the response | string | Optional |
sample code
import requests
URL = "https://api.kadal.ai/aiwb/metering/api/v1/"
# sample python code
headers = { "Authorization ": "Bearer 1234567890" }
params:{
"bot_id": "string",
"application_name": "string",
"unique_query_id": "string",
"user_query": "string",
"model_answer": "string",
"model_type": "string",
"model_name": "string",
"pre_calc_input_token": 0,
"input_token": 0,
"output_token": 0,
"metering_costs": {
"input_token_cost": 0,
"output_token_cost": 0,
"av_translation_cost": 0,
"embedding_cost": 0,
"total_cost": 0
},
"input_payload": "string",
"model_response": "string",
"metering_logs": {
"av_translation_duration": 0,
"image_generation_nos": 0,
"image_generation_quality": 0,
"image_generation_dimension": "string"
},
"latency_in_seconds": 0,
"word_count_sent": 0,
"word_count_received": 0,
"toxicity": "Toxic",
"sentiment": "Positive"
}
response = requests.post(URL, headers=headers,params=params)
print(response)
Example Response value -
{
"status_code": 201,
"message": "Token consumption created successfully"
}
Responses:
Status Code | Description | Content-Type |
---|---|---|
200 | Successful Response | application/json |
201 | Token consumption created successfully | application/json |
400 | Bad Request | application/json |
500 | Internal Server Error | application/json |
422 | Validation Error | application/json |
Token Consumption by Tenant -
Endpoint: /aiwb/metering/api/v1/token_by_tenant/{tenant_id}
- Method:
GET
- Summary: Retrieve the Usage Details of Tokens Consumed by a Specific Tenant
- Description: This API endpoint enables retrieval of token consumption data associated with a specific Tenant ID. By making a GET request to this endpoint with the relevant Tenant ID specified as a parameter, you can obtain detailed information about token usage within the specified tenant.
- Operation ID:
Retrieve_the_usage_details_of_tokens_consumed_by_a_specific_tenant_aiwb_metering_api_v1_token_by_tenant__tenant_id__get
Request Payload:
Type | Parameter | Description | Data Type | is_optional |
---|---|---|---|---|
parameter | tenant_id | Tenant ID to retrive metering | string (UUID) | mandatory |
Sample code
import requests
URL = "https://api.kadal.ai/aiwb/metering/api/v1/token_by_tenant/{tenant_id}"
# sample python code
headers = { "Authorization ": "Bearer 1234567890" }
params:{
"tenant_id":"string"
}
response = requests.get(URL, headers=headers,params=params)
print(response)
Example Response value -
{
"status_code": 200,
"message": "List of token consumed by Tenant Id"
}
Responses:
Status Code | Description | Content-Type |
---|---|---|
200 | List Token consumed by Tenant ID | application/json |
404 | Token consumption not found for given tenant | application/json |
400 | Bad Request | application/json |
500 | Internal Server Error | application/json |
422 | Validation Error | application/json |
Token Consumption by User -
Endpoint: /aiwb/metering/api/v1/token_by_user/{user_id}
- Method:
GET
-- Summary: Retrieve the Usage Details of Tokens Consumed by a Specific User
- Description: This API allows you to retrieve a list of tokens consumed by a specific User. By sending a GET request to this endpoint with the UserId as a parameter, you can access detailed information about token consumption associated with that user.
- Operation ID:
Retrieve_the_usage_details_of_tokens_consumed_by_a_specific_user_aiwb_metering_api_v1_token_by_user__user_id__get
Request Payload:
Type | Parameter | Description | Data Type | is_optional |
---|---|---|---|---|
parameter | user_id | user ID to retrive metering | string (UUID) | mandatory |
Sample code
import requests
URL = "https://api.kadal.ai/aiwb/metering/api/v1/token_by_user/{user_id}"
# sample python code
headers = { "Authorization ": "Bearer 1234567890" }
params:{
"user_id":"string"
}
response = requests.get(URL, headers=headers,params=params)
print(response)
Example Response value -
{
"status_code": 200,
"message": "List of token consumed by UserId"
}
Responses:
Status Code | Description | Content-Type |
---|---|---|
200 | List of Tokens consumed by UserId | application/json |
404 | Token consumption not found for given user | application/json |
400 | Bad Request | application/json |
500 | Internal Server Error | application/json |
422 | Validation Error | application/json |
Components
Schemas
HTTPValidationError
- Type: object
- Description:
- Properties:
- detail:
- Type: array
- detail:
ListTokenConsumedResponse
- Type: object
- Description:
- Properties:
- status_code:
- Type: integer
- message:
- Type: string
- data:
- status_code:
MeteringResponse
- Type: object
- Description:
- Properties:
- status_code:
- Type: integer
- message:
- Type: string
- status_code:
Msg
- Type: object
- Description:
- Properties:
- msg:
- Type: string
- msg:
Sentiment
- Type: Not specified
- Description: An enumeration.
- Properties:
TokenConsumption
- Type: object
- Description:
- Properties:
- bot_id:
- Type: string
- application_name:
- Type: string
- unique_query_id:
- Type: string
- user_query:
- Type: string
- model_answer:
- Type: string
- model_name:
- Type: string
- pre_calc_input_token:
- Type: integer
- input_token:
- Type: integer
- output_token:
- Type: integer
- input_payload:
- model_response:
- latency_in_seconds:
- Type: number
- word_count_sent:
- Type: integer
- word_count_received:
- Type: integer
- toxicity:
- sentiment:
- bot_id:
Toxicity
- Type: Not specified
- Description: An enumeration.
- Properties:
ValidationError
- Type: object
- Description:
- Properties:
- loc:
- Type: array
- msg:
- Type: string
- type:
- Type: string
- loc: